package cat.inkubator.plugin4j;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;

/**
 *
 * @author gato
 */
public class MessageFrame extends JDialog implements Runnable{

    private JProgressBar current;
    private JLabel label;

    public MessageFrame( String message, JFrame parent ) {
        super(parent, true);

        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JPanel pane = new JPanel();
        pane.setLayout(new BorderLayout());

        current = new JProgressBar();
        current.setValue(0);
        current.setIndeterminate(true);

        label = new JLabel(message);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        current.setCursor(new Cursor(Cursor.WAIT_CURSOR));

        pane.add(label, BorderLayout.NORTH);
        pane.add(current, BorderLayout.SOUTH);
        setContentPane(pane);
        this.setUndecorated(true);
        this.setAlwaysOnTop(true);

        // Get the size of the screen
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        // Determine the new location of the window
        int w = this.getSize().width;
        int h = this.getSize().height;
        int x = (dim.width-w)/2-100;
        int y = (dim.height-h)/2;

        // Move the window
        this.setLocation(x, y);
    }

    public void run(){
        this.pack();
        this.setVisible(true);
    }

    public void setMessage(String message) {
        this.label.setText(message);
    }

}